SOFIADIR := deps/sofia_sdk/Lib/aarch64-himix100-linux-
MVSLIBDIR := deps/mvs_sdk/lib/aarch64
HISILIBDIR := deps/hisi_sdk/lib
ALGODIR := deps/algo
SRC := $(wildcard *.c)
SRC += $(wildcard modbus/*.c)
SRC += $(wildcard *.cpp)

ALGO_CFLAGS = -fPIC -shared -fsigned-char -fpermissive -Wall -O0 -g -Ideps/opencv/include
ALGO_LDLIBS = -lstdc++ -lpthread -ldl -lm 
ALGO_LDLIBS += deps/opencv/lib/libopencv_imgproc.a deps/opencv/lib/libopencv_core.a deps/opencv/lib/libopencv_hal.a 
# 依赖静态opencv库需要添加zlib库， 否则报错
ALGO_LDLIBS += deps/opencv/share/OpenCV/3rdparty/lib/libzlib.a

TARGET := mtapp
CC = aarch64-himix100-linux-g++
X86_CC = gcc
INCFLAGS = -Ideps/hisi_sdk/include -Ideps/sofia_sdk -Ideps/mvs_sdk/include -Isrc/modbus -Ideps/algo -Ideps/opencv/include
CFLAGS = -fPIC -fsigned-char -fpermissive -Wall -O0 -g $(INCFLAGS)
LDLIBS = -lstdc++ -lpthread -ldl -lm
LDLIBS += $(HISILIBDIR)/libmpi.a $(HISILIBDIR)/libupvqe.a $(HISILIBDIR)/libVoiceEngine.a $(HISILIBDIR)/libdnvqe.a $(HISILIBDIR)/libsecurec.a
LDLIBS += $(MVSLIBDIR)/libMvCameraControl.so
#LDLIBS += $(ALGODIR)/libstrickle/libMT_Strickle_Alg.so
LDLIBS += $(ALGODIR)/libvolume/libMT_AreaCaculate_Alg.so
LDLIBS += $(ALGODIR)/libbelt/libBeltTearDetecte_Alg.so
LDLIBS += $(ALGODIR)/libdebris/libMT_LDD_Alg.so
LDLIBS += $(ALGODIR)/libspray/libspray.so
LDLIBS += $(ALGODIR)/libtarpa/libtarpa.so
LDLIBS += $(SOFIADIR)/libNetSdk.a $(SOFIADIR)/libFoundation.a $(SOFIADIR)/libuuid.a $(SOFIADIR)/libHttp.a $(SOFIADIR)/libez_libs.a $(SOFIADIR)/libjson.a $(SOFIADIR)/libmosquitto.a
LDFLAGS = -Wl,-rpath=$(MVSLIBDIR),-rpath=$(ALGODIR)/libvolume,-rpath=$(ALGODIR)/libbelt,-rpath=$(ALGODIR)/libdebris
LDFLAGS += -Wl,-rpath=$(ALGODIR)/libtarpa,-rpath=$(ALGODIR)/libspray#,-rpath=$(ALGODIR)/libstrickle



BOM = {$(TARGET),config,VolumeDetect_711.json,background.yuv}
BOM_LIB = deps/algo

all: $(TARGET)

VER_TYPE ?= inner_test

$(TARGET): $(SRC) 
	$(CC) $(SRC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(ALGO_LDLIBS) -o $@
	
#苫布算法
libtarpa.so : tarpa/tarpa.cpp
	$(CC) $^ $(ALGO_CFLAGS) $(ALGO_LDLIBS) -o $@ 
	mv $@ deps/algo/libtarpa
	
#喷淋算法
libspray.so : spray/sprayAlgo.cpp
	$(CC) $^ $(ALGO_CFLAGS) $(ALGO_LDLIBS) -o $@ 
	mv $@ deps/algo/libspray

#刮板算法
libMT_Strickle_Alg.so : strickle/MT_Strickle_Alg.cpp
	$(CC) $^ $(ALGO_CFLAGS) $(ALGO_LDLIBS) -o $@ 
	mv $@ deps/algo/libstrickle

pkg:
	cp $(BOM) mtpkg/algmodel
	cp -R $(BOM_LIB) mtpkg/algmodel/deps 
	cd mtpkg && sudo make VER_TYPE=$(VER_TYPE)

echo:
	@echo "SRC files:"
	@echo $(SRC)
	@echo "CFLAGS:"
	@echo $(CFLAGS)
	@echo "LDFLAGS:"
	@echo $(LDFLAGS)
	@echo "LDLIBS:"
	@echo $(LDLIBS)

clean:
	@-rm -rf $(TARGET) *.bak .*.bak
	@-rm -rf mtpkg/dist/*

.PHONY:echofile clean pkg